<?php

namespace App\Models\Chat;

use App\Models\BaseModel;
use App\Models\ChatUsers;
use Illuminate\Database\Eloquent\Model;


/**
 * Model ChatFriendApplyModel
 *
 * @property int $id
 * @property int $fid
 * @property int $tid
 * @property string $msg
 * @property string $create_time
 * @property int $status
 *
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel where($column, $operator = null, $value = null, $boolean = 'and')
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel whereIn($column, $values, $boolean = 'and', $not = false)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel leftJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel rightJoin($table, $first, $operator = null, $second = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel get($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null)
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel find($id, $columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel first($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel select($columns = ['*'])
 * @method static \Illuminate\Database\Query\Builder | \App\Models\Chat\ChatFriendApplyModel orderBy($column, $direction = 'asc')
 * @package App\Model
 */

class ChatFriendApplyModel extends BaseModel
{
    protected $table = 'chat_friend_apply';

    public $timestamps = false;
    public function filter($data)
    {
        //
        $where = [];
        if (isset($data['id']))
        {
            $where[] = ['id', '=', $data['id']];
        }
        if (isset($data['is_valid']))
        {
            $where[] = ['is_valid', '=', $data['is_valid']];
        }
        $this->getQueryByModel()->where($where);

        if ($this->getQueryByModel()->hasNamedScope("filter") && class_exists($this->getModelFilterClass())) {
            $this->getQueryByModel()->filter($data);
        }

        return $this->getQueryByModel();
    }

    // 申请人信息
    public function tInfo()
    {
        return $this->hasOne(ChatUsers::class,'id','tid')->select(['id','nickname','avatar','mini_avatar','area','signature','sex']);
    }
    // 接收人信息
    public function fInfo()
    {
        return $this->hasOne(ChatUsers::class,'id','fid')->select(['id','nickname','avatar','mini_avatar','area','signature','sex']);
    }
}
